package com.lin;

import com.lin.commands.CommandFactory;
import com.lin.commands.CommandProccesor;
import com.lin.commands.RailRoadServiceCommandFactory;
import com.lin.service.RailRoadService;
import com.lin.service.RailRoadServiceImpl;
import com.lin.util.TownConfig;
import com.lin.util.TownConfigImpl;

import java.io.FileNotFoundException;

public class Main {
    public static void main(String[] args) {
        if (args.length != 2) {
            System.err.println("usage:  graph.txt , commands.txt");
            System.exit(1);
        } else {
            String graphFilePath = args[0];
            String commandsFilePath = args[1];

            TownConfig config = new TownConfigImpl();
            try {
                config.init(graphFilePath);

                RailRoadService service = new RailRoadServiceImpl(config);

                // Create an CommandFactory
                CommandFactory commandFactory = new RailRoadServiceCommandFactory(service);

                // Create an CommandProccesor that uses commandFactory
                CommandProccesor processor = new CommandProccesor(commandFactory);

                System.out.println(processor.runAll(commandsFilePath));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
}
